//
//  MicrophoneAlertView.m
//  MicrowaveLight
//
//  Created by Kendama on 2017/6/26.
//  Copyright © 2017年 DT. All rights reserved.
//

#import "MicrophoneAlertView.h"
@interface MicrophoneAlertView ()
/** 背景 **/
@property(nonatomic,strong) UIView *bgView;
/** 标题 **/
@property(nonatomic,strong) UILabel *titleLabel;
/** 副标题 **/
@property(nonatomic,strong) UILabel *textLabel;

@end

@implementation MicrophoneAlertView

- (instancetype)init{
    
    if ([super init]) {
        [self masLayoutSubview];
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0];
    }
    return self;
}

/**
 取消按钮点击事件
 */
- (void)cancelAction:(UIButton *)sender
{
    [self calloutAnimation];
    if (self.cancel_block) {
        self.cancel_block(sender);
    }
}

- (void)callinAnimation
{
    [UIView transitionWithView:self duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    } completion:nil];
}

- (void)calloutAnimation
{
    [UIView animateWithDuration:0.5 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        if (finished) {
            [self removeFromSuperview];
        }
    }];
}


#pragma mark -- 懒加载
- (TEABarChart *)barChart
{
    if(!_barChart)
    {
        UIView *superView = self;
        _barChart = [[TEABarChart alloc]init];
        [superView addSubview:_barChart];
    }
    return _barChart;
}


- (UIView *)bgView
{
    if (!_bgView) {
        UIView *superView = self;
        _bgView = [[UIView alloc]init];
        [superView addSubview:_bgView];
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.masksToBounds = YES;
        _bgView.layer.cornerRadius = 4.f;
    }
    return _bgView;
}

- (UIButton *)cancelButton
{
    if (!_cancelButton) {
        UIView *superView = self.bgView;
        _cancelButton = [[UIButton alloc]init];
        [superView addSubview:_cancelButton];
        [_cancelButton setTitle:@"取消" forState:UIControlStateNormal];
        [_cancelButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [_cancelButton addTarget:self action:@selector(cancelAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cancelButton;
}

- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        UIView *superView = self.bgView;
        _titleLabel = [[UILabel alloc]init];
        [superView addSubview:_titleLabel];
        _titleLabel.text = @"麦克律动";
        [_titleLabel setFont:[UIFont systemFontOfSize:17]];
    }
    return _titleLabel;
}


- (void)masLayoutSubview
{
    UIView *superView = self;
    [self.bgView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(superView.mas_centerX);
        make.centerY.mas_equalTo(superView.mas_centerY);
        make.height.mas_equalTo(px1920Height(650));
        make.width.mas_equalTo(px1080Width(900));
    }];
    
    [self.cancelButton mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.bgView.mas_right).mas_offset(-px1080Width(14));
        make.left.mas_equalTo(self.bgView.mas_left).mas_offset(px1080Width(14));
        make.height.mas_equalTo(px1920Height(130));
        make.bottom.mas_equalTo(self.bgView.mas_bottom);
    }];
    
    UIView *line = [[UIView alloc] init];
    [self.bgView addSubview:line];
    line.backgroundColor = [UIColor colorWithRed:236/255.0 green:236/255.0 blue:237/255.0 alpha:1];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.cancelButton);
        make.left.mas_equalTo(self.cancelButton);
        make.height.mas_equalTo(1);
        make.bottom.mas_equalTo(self.cancelButton.mas_top);
    }];
    
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.bgView.mas_top).mas_offset(px1920Height(55));
        make.centerX.mas_equalTo(self.bgView.mas_centerX);
    }];
    

    [self.barChart mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.titleLabel.mas_bottom ).mas_offset(20);
        make.left.mas_equalTo(self.bgView.mas_left).mas_offset(px1080Width(43));
        make.right.mas_equalTo(self.bgView.mas_right).mas_offset(-px1080Width(43));
        make.height.mas_equalTo(px1920Height(260));
    }];
    
    
}


@end
